# Maintainer: Renato Silva <br.renatosilva@gmail.com>

_realname=libmongoose
pkgbase="mingw-w64-${_realname}"
pkgname=(${MINGW_PACKAGE_PREFIX}-${_realname})
replaces=(${MINGW_PACKAGE_PREFIX}-${_realname}-git)
pkgver=7.11
pkgrel=1
url="https://github.com/cesanta/mongoose"
pkgdesc='Embedded web server for C/C++ (mingw-w64)'
license=('GPL2')
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64' 'clang32')
depends=(${MINGW_PACKAGE_PREFIX}-gcc-libs)
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
source=(${_realname}-${pkgver}.tar.gz::"https://github.com/cesanta/mongoose/archive/${pkgver}.tar.gz"
        mongoose.pc
        Makefile)
noextract=(${_realname}-${pkgver}.tar.gz)
sha256sums=('728c94b764a54dd5fc0358bdfd2c9fee26b8e8fe65d4bb89c2a6ce70bcc91ce4'
            '7ff212f0d496a1082282f4722113084f9037d7c501ec90ca124e4de0cc2b2545'
            '7ca7ecff9d1e16ab7cde71698509f8b5d002f56ec33b797f5ff0ef8c9e06371c')

prepare() {
  tar -xzf ${srcdir}/${_realname}-${pkgver}.tar.gz -C ${srcdir} || true

  cp Makefile mongoose-${pkgver}/
  cp mongoose.pc mongoose-${pkgver}/
}

build() {
  cd "${srcdir}/mongoose-${pkgver}"
  make PREFIX=${MINGW_PREFIX} CC=cc AR=ar -j1
}

package() {
  cd "${srcdir}/mongoose-${pkgver}"
  make PREFIX=${MINGW_PREFIX} DESTDIR=${pkgdir} install
  install -D -m644 mongoose.pc "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/mongoose.pc"
  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"

  sed -e "s|@@PREFIX@@|${MINGW_PREFIX}|g" \
      -e "s|@@VERSION@@|${pkgver}|g" \
      -i "${pkgdir}${MINGW_PREFIX}/lib/pkgconfig/mongoose.pc"
}
